//
// Created by luoen on 19-7-16.
//

#ifndef IALGORITHM_LINKED_LIST_H
#define IALGORITHM_LINKED_LIST_H

#include <stdint.h>

typedef struct list_node {
    void * data;
    struct list_node * pre;
    struct list_node * next;
} listNode;

typedef struct linked_list {
    char type;//0-单向链表,1-双向链表,2-双向循环链表
    listNode * head;
    listNode * tail;
    size_t length;
    void (*free)(void*);
} linkedList;

linkedList* _create_linked_list(char type);

linkedList* _insert_node(linkedList* list, listNode* node, size_t index);
linkedList* _insert_data(linkedList* list, void * data, size_t index);
linkedList* _insert_node_to_head(linkedList* list, listNode* node);
linkedList* _insert_data_to_head(linkedList* list, void * data);
linkedList* _insert_node_to_tail(linkedList* list, listNode* node);
linkedList* _insert_data_to_tail(linkedList* list, void * data);
linkedList* _delete_data(linkedList* list, void* data);
linkedList* _delete_node(linkedList* list, listNode* node);
linkedList* _reverse_linked_list(linkedList* list);
listNode* _find_node_by_index(linkedList* list, size_t index);
listNode* _find_node_by_data(linkedList* list, void* data);
void _empty_linked_list(linkedList* list);
void _release_linked_list(linkedList* list);
size_t _linked_list_length(linkedList* list);

#endif //IALGORITHM_LINKED_LIST_H